//
//  JZHFrendPulisViewController.m
//  极致荟
//
//  Created by hetao on 14-5-11.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHFrendPulisViewController.h"
#import "JZHFrendePulisTableViewCell.h"
#import "OtherUsers.h"
#import "FriendRequest.h"
@interface JZHFrendPulisViewController ()
{
    NSMutableArray *dataarr;
    NSString * rfdtime;
}
@end

@implementation JZHFrendPulisViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [FriendRequest dorpRN];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
   
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title=@"好友验证";
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setFont:[UIFont systemFontOfSize:14.0]];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nuberfr:) name:SENDREQUEST object:nil];
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 5)];
    [rightButton addTarget:self action:@selector(rightDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [rightButton setFrame:CGRectMake(0, 0, 50, 10)];
        [rightButton setTitle:@"清空" forState:UIControlStateNormal];
        [rightButton setTitleColor:TEXTBULE forState:UIControlStateNormal];
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButton;
    dataarr=[[NSMutableArray alloc]init];
    [self httpLoadData];
}

- (void)nuberfr:(NSNotification *)not
{
    [self dbdata];
}
- (void)httpLoadData
{
    [self dbdata];
    
    [FriendRequest HttpFriendRequestcomYes:^(NSMutableArray *arr, NSString* rptime) {
        rfdtime=rptime;
        [self dbdata];
    }];
    

}

- (void)dbdata
{
    dataarr= [FriendRequest selectFriend];
    [self.table reloadData];
}
- (void)leftDrawerButtonPress:(UIButton *)but
{
    [UINavigationController Pop:self];
}

- (void)rightDrawerButtonPress:(UIButton *)but
{
    [[[UIAlertView alloc] initWithTitle:@"提示" message:@"要清空好友请求列表吗？" delegate:self  cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return dataarr.count;
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==1)
    {
        NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:rfdtime,@"lastPushTime", nil];
        [HttpRequest httpRequestPost:JZHHTTPURL(@"friends/cleanRespondList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
            NSLog(@"%@",data);
            [FriendRequest dorpRNList];
            [UINavigationController Pop:self];
        }];
    }
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 111;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str=@"adf";
    JZHFrendePulisTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"JZHFrendePulisTableViewCell" owner:self options:nil] objectAtIndex:0];
        cell.mesg=self;
        
    }
    [cell addCellData:dataarr[indexPath.row]];
    return cell;
}


@end
